#ifndef PROCESS_MANAGEMENT_H
#define PROCESS_MANAGEMENT_H

#include "registers.h"
#include "message_passing.h"
#include "process_supervision.h"
#include "scheduler.h"

#define NUMBER_MAX_PROCESSES 100
#define MAX_PRIORITY 30

/* type declarations */

typedef struct{
	uint8_t in_use;
	uint32_t priority;
	uint32_t pid;
	registers_t registers;
	message message_queue[MAX_NUMBER_MESSAGES]; //fixed length of 20 messages
	struct PCB* supervisors[MAX_SUPERVISORS];
}PCB;

/* global variables */

/* this array contains all the PCBs. Until we have a way to allocate memory dynamically, its size is fixed and each PCB has a flag in_use indicating whether it is being used or not */
PCB processes[NUMBER_MAX_PROCESSES];

/* function declarations */

/* initializes the global array processes */
void initialize_processes_table();

/* creates a new process (with priority as priority level) by allocating a PCB to it and returns its pid */
uint32_t create_process(uint32_t priority);

/* removes the PCB of the process pid */
void remove_process(uint32_t pid);

/* saves the contents of the registers in the PCB of the process pid */
void context_switch_save(uint32_t pid);

/* loads the contents of ther registers from the PCB of the process pid (both this function and the one above will be mostly written in assembly) */
void context_switch_load(uint32_t pid);
#endif
